package com.allinpay.merchantweb.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.allinpay.merchantweb.common.utils.SequenceUtil;
import com.allinpay.merchantweb.constants.ReturnCodeConstants;
import com.allinpay.merchantweb.model.FinancialProdInfo;
import com.allinpay.merchantweb.model.FinancialProdInfoVo;
import com.allinpay.merchantweb.request.CommonReqBean;
import com.allinpay.merchantweb.response.AppCommonResponse;
import com.allinpay.merchantweb.response.ResponseData;
import com.allinpay.merchantweb.service.IAllinpayProductionService;
import com.google.gson.reflect.TypeToken;

@Service
public class AllinpayProductionServiceImpl implements IAllinpayProductionService{

	@Autowired
	RestRequestService restRequestService;
	
	


	@Override
	public ResponseData<FinancialProdInfoVo> queryFinancialProds(FinancialProdInfo prodInfo) throws Exception {
		// TODO Auto-generated method stub
		CommonReqBean reqBean = new CommonReqBean(); 
		reqBean.setBizContent(prodInfo);
		reqBean.setReqSsn(SequenceUtil.getAppReqSsn());
		
		
		AppCommonResponse<ResponseData<FinancialProdInfoVo>> respBean = restRequestService.postToAppForSingleByObj
				("/allinpayProduction/queryFinancialProdList"
						, reqBean
						, new TypeToken<AppCommonResponse<ResponseData<FinancialProdInfoVo>>>() {}.getType());
		if( respBean != null &&  respBean.getSubCode() != null 
				&& respBean.getSubCode().equals(ReturnCodeConstants.SUB_CODE_SUCC)) {			
			List<FinancialProdInfoVo> prodList = respBean.getData().getDataList();
			for( FinancialProdInfoVo prodInfoTp : prodList ) {
				prodInfoTp.translateSomeItems();
			}
			return respBean.getData();
		}else {
			throw new Exception("queryFinancialProds error:" + respBean.getSubMsg());
		}
	}

	@Override
	public Object addFinancialProd(FinancialProdInfo prodInfo) throws Exception {
		// TODO Auto-generated method stub
		CommonReqBean reqBean = new CommonReqBean(); 
		reqBean.setBizContent(prodInfo);
		reqBean.setReqSsn(SequenceUtil.getAppReqSsn());
		
		
		AppCommonResponse<ResponseData> respBean = restRequestService.postToAppForSingleByObj
				("/allinpayProduction/addFinancialProd"
						, reqBean
						, new TypeToken<AppCommonResponse<ResponseData>>() {}.getType());
		if( respBean != null &&  respBean.getSubCode() != null 
				&& respBean.getSubCode().equals(ReturnCodeConstants.SUB_CODE_SUCC)) {			

			return respBean.getData();
		}else {
			throw new Exception("addFinancialProd error:" + respBean.getSubMsg());
		}
	}

	@Override
	public Object deleteEnterpriseProd(FinancialProdInfo prodInfo) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object updateFinancialProd(FinancialProdInfo prodInfo, Integer instanceId, String accountCode)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}


}
